﻿Imports Mystery

Public Class passwordControl
    Implements IPropertyControl

    Private _property_info As System.Reflection.PropertyInfo
    Private _content_property As ContentProperty


    Public Property property_info As System.Reflection.PropertyInfo Implements IPropertyControl.property_info
        Get
            Return _property_info
        End Get
        Set(value As System.Reflection.PropertyInfo)
            _content_property = value.getMysteryAttribute(Of ContentProperty)()
            _label = _content_property.label
            _property_info = value
        End Set
    End Property

    Private _content As User

    Public Property content_item As Mystery.IContent Implements IPropertyControl.content
        Get
            Return _content
        End Get
        Set(value As Mystery.IContent)
            _content = value

        End Set
    End Property

    Private _label As String
    Public ReadOnly Property label As String Implements IPropertyControl.label
        Get
            Return _label
        End Get
    End Property

    Dim auth As IAuthetication = getGlobalObject(Of IAuthetication)()

    Public Function setInContent() As System.Collections.Generic.IEnumerable(Of Mystery.IContent) Implements IPropertyControl.setInContent
        Dim result As New List(Of IContent)
        If _content Is Nothing Then Return result

        If Not String.IsNullOrEmpty(new_password.Password) AndAlso
            Not String.IsNullOrEmpty(_content.password) AndAlso
            _content.password.value <> auth.Hashstring(Me.curret_password.Password) Then

            MsgBox("wrong current password")
            Return result
        End If

        If Not String.IsNullOrEmpty(new_password.Password) Then
            _content.password = CStr(Me.value)
        End If


        result.Add(_content)

        Return result

    End Function

    Public Property value As Object Implements IPropertyControl.value
        Get
            Return auth.Hashstring(new_password.Password)
        End Get
        Set(value As Object)

        End Set
    End Property

    Public ReadOnly Property wished_height As System.Windows.GridLength Implements IPropertyControl.wished_height
        Get
            Return GridLength.Auto
        End Get
    End Property

    Public Event valueChanged() Implements IPropertyControl.valueChanged

    Private Sub new_password_PasswordChanged(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles new_password.PasswordChanged
        RaiseEvent valueChanged()
    End Sub
End Class
